import { ApiProperty } from '@nestjs/swagger';
import { IsInt, IsString } from 'class-validator';
import {
  Column,
  CreateDateColumn,
  Entity,
  PrimaryGeneratedColumn,
  UpdateDateColumn,
} from 'typeorm';

@Entity()
export class AppUser {
  @ApiProperty({ description: '用户id' })
  @PrimaryGeneratedColumn()
  id: number;

  @ApiProperty({ description: 'uuid' })
  @IsString()
  @Column({ nullable: true })
  userId: string;

  @ApiProperty({ description: '用户名' })
  @IsString()
  // @Length(1, 255)
  @Column({ nullable: true })
  name: string;

  @ApiProperty()
  @IsString()
  @Column({ nullable: true })
  avatar: string;

  @ApiProperty({ description: 'vip级别, 0否1是' })
  @IsInt()
  @Column({ nullable: true })
  vipLevel: number;

  @ApiProperty({ title: '产品id', description: '如果是vip则为对应的产品id' })
  @IsString()
  @Column({ nullable: true })
  productId?: string;

  @ApiProperty()
  @CreateDateColumn({ type: 'timestamptz', default: () => 'CURRENT_TIMESTAMP' })
  createdAt: string;

  @ApiProperty()
  @Column({ nullable: true })
  vipExpiredAt: string;

  @ApiProperty()
  @UpdateDateColumn({
    type: 'timestamptz',
    default: () => 'CURRENT_TIMESTAMP',
    onUpdate: 'CURRENT_TIMESTAMP',
  })
  updatedAt: string;
}
